﻿using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using AutoPoco;
using AutoPoco.DataSources;
using AutoPoco.Engine;
using InvoiceProject.Controllers;
using InvoiceProject.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using InvoiceProject.Enums;
using Moq;
using NUnit.Framework;
using TestContext = Microsoft.VisualStudio.TestTools.UnitTesting.TestContext;

namespace InvoiceProject.Tests.BaseModelUnitTests
{


    /// <summary>
    ///This is a test class for BusinessTest and is intended
    ///to contain all BusinessTest Unit Tests
    ///</summary>


    [TestClass()]
    public class WhenSavingAnObjectThatInheritsBaseModel
    {

        [TestMethod()]
        public void ShouldPassWhenValidAttributesArePresent()
        {
            BaseModel baseModel = new BaseModel
                                  {
                                    //  DateCreated = DateTime.Now,
                                      DateModified = DateTime.Now,
                                     // UserCreated = "IF222",
                                      UserModified = "IF2222"
                                  };


            var validationContext = new ValidationContext(baseModel, null, null);
            Validator.ValidateObject(baseModel, validationContext);


        }

        //[TestMethod()]
        //[Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedException(typeof(ValidationException))]
        //public void ShouldFailWhenDateCreatedIsNotSupplied()
        //{
        //    BaseModel baseModel = new BaseModel
        //    {
        //       // DateCreated = DateTime.Now,
        //        DateModified = DateTime.Now,
        //     //   UserCreated = "IF222",
        //        UserModified = "IF2222"
        //    };

        //    var validationContext = new ValidationContext(baseModel, null, null);
        //    Validator.ValidateObject(baseModel, validationContext);

        //}

        [TestMethod()]
        [Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedException(typeof(ValidationException))]
        public void ShouldFailWhenDateModifiedIsNotSupplied()
        {
            BaseModel baseModel = new BaseModel
            {
             //   DateCreated = DateTime.Now,
             //   DateModified = DateTime.Now,
               // UserCreated = "IF222",
                UserModified = "IF2222"
            };


            var validationContext = new ValidationContext(baseModel, null, null);
            Validator.ValidateObject(baseModel, validationContext);

        }

        //[TestMethod()]
        //[Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedException(typeof(ValidationException))]
        //public void ShouldFailWhenUserCreatedIsNotSupplied()
        //{
        //    BaseModel baseModel = new BaseModel
        //    {
        //     //   DateCreated = DateTime.Now,
        //        DateModified = DateTime.Now,
        //      //  UserCreated = "IF222",
        //        UserModified = "IF2222"
        //    };


        //    var validationContext = new ValidationContext(baseModel, null, null);
        //    Validator.ValidateObject(baseModel, validationContext);

        //}

        [TestMethod()]
        [Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedException(typeof(ValidationException))]
        public void ShouldFailWhenUserModifiedIsNotSupplied()
        {
            BaseModel baseModel = new BaseModel
            {
              //  DateCreated = DateTime.Now,
                DateModified = DateTime.Now,
              //  UserCreated = "IF222",
              // UserModified = "IF2222"
            };


            var validationContext = new ValidationContext(baseModel, null, null);
            Validator.ValidateObject(baseModel, validationContext);

        }
  
    
    
    
    }
    
    }